<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import desginTemplate from "./desginTemplate/index";
import goodsList from "./goodsList/index";
import storeGroup from "./storeGroup/index";
export default {
  components: {
    desginTemplate,
    goodsList,
    storeGroup,
  },
  computed: {
    typeOption() {
      let _list = [];
      if (this.selected.path != "") {
        let _d = [];
        this.list.forEach((item) => {
          item.children.forEach((iitem) => {
            if (iitem.toPath == this.selected.path) {
              console.error("this.selected.path", iitem.toTypeList);
              _d = iitem.toTypeList;
            }
          });
        });
        console.log("_d", _d, this.$vFN.Utils.isEmpty(_d));
        if (!this.$vFN.Utils.isEmpty(_d)) {
          _list = _d;
        } else {
          _list = ["navigate", "reLaunch", "redirect"];
        }
      } else {
        _list = ["navigate", "reLaunch", "redirect"];
      }
      // 如果跳转方式列表不符合当前路径 则重置
      let _is = _list.some((item) => {
        return this.selected.type == item;
      });
      if (!_is) {
        this.selected.type = _list[0];
      }

      let _data = [];

      _list.forEach((item) => {
        let _obj = this.$vFN.Tools.getLinkTypeOption(item);
        _data.push(_obj);
      });

      console.error("_list", _list, [..._data]);

      return _data;
    },
  },
  data() {
    return {
      // 外部传入
      appWindow: null,
      selected: {
        query: {},
        path: "",
        type: "",

        name: "",
      },

      selectedIndex: 0,
      list: [
        {
          name: "系统页面",
          children: [
            {
              name: "首页",
              toType: "switchTab",
              toTypeList: ["switchTab", "reLaunch"],
              toPath: "/pages/home/index",
              query: {},
              tips: "TabBar页面",
            },
            {
              name: "分类",
              toType: "switchTab",
              toTypeList: ["switchTab", "reLaunch"],
              toPath: "/pages/classify/index",
              query: {},
              tips: "TabBar页面",
            },
            {
              name: "购物车",
              toType: "switchTab",
              toTypeList: ["switchTab", "reLaunch"],
              toPath: "/pages/cart/index",
              query: {},
              tips: "TabBar页面",
            },
            {
              name: "我的",
              toType: "switchTab",
              toTypeList: ["switchTab", "reLaunch"],
              toPath: "/pages/mine/index",
              query: {},
              tips: "TabBar页面",
            },
          ],
        },
        {
          name: "功能页面",
          children: [
            {
              name: "副购物车",
              toType: "navigate",
              toPath: "/pages/cartSub/index",
              query: {},
              tips: "非TabBar购物车页，支持后退。",
            },
            {
              name: "收货地址管理",
              toType: "navigate",
              toPath: "/packSub/addressList/index",
              query: {},
              tips: "",
            },
            {
              name: "门店聚合页",
              toType: "navigate",
              toPath: "/packStore/main/index",
              query: {},
              tips: "",
            },
            {
              name: "收货地址选择",
              toType: "navigate",
              toPath: "/packAddress/list/index",
              query: { type: 1 },
              tips: "选择后可从缓存读取已选数据",
            },
            {
              name: "收货地址编辑",
              toType: "navigate",
              toPath: "/packAddress/edit/index",
              query: {},
              tips: "",
            },

            {
              name: "商品搜索页面",
              toType: "navigate",
              toPath: "/packShop/goodsSearch/index",
              query: {},
              tips: "",
            },
            {
              name: "绑定支付宝",
              toType: "navigate",
              toPath: "/packAssets/setAliPay/index",
              query: {},
              tips: "",
            },
            {
              name: "我的优惠券",
              toType: "navigate",
              toPath: "/packAssets/couponLog/index",
              query: {},
              tips: "",
            },
            {
              name: "我的收藏",
              toType: "navigate",
              toPath: "/packAssets/collectLog/index",
              query: {},
              tips: "",
            },
            {
              name: "我的银行卡列表",
              toType: "navigate",
              toPath: "/packAssets/bankCardList/index",
              query: {},
              tips: "",
            },
            {
              name: "绑定手机号",
              toType: "navigate",
              toPath: "/packSub/bindMobile/index",
              query: {},
              tips: "",
            },
            {
              name: "修改密码",
              toType: "navigate",
              toPath: "/packSub/updatePwd/index",
              query: {},
              tips: "",
            },
            {
              name: "商家申请",
              toType: "navigate",
              toPath: "/packStore/merchantManage/index",
              query: {},
              tips: "",
            },
            {
              name: "收益",
              toType: "navigate",
              toPath: "/packIncome/home/index",
              query: {},
              tips: "",
            },
            {
              name: "个人基本信息设置",
              toType: "navigate",
              toPath: "/packSub/personalInformation/index",
              query: {},
              tips: "",
            },
            {
              name: "商城核销员",
              toType: "navigate",
              toPath: "/packShop/shopVerification/index",
              query: {},
              tips: "",
            },
            {
              name: "门店核销员",
              toType: "navigate",
              toPath: "/packStore/storeVerification/index",
              query: {},
              tips: "",
            },
            {
              name: "资产中心",
              toType: "navigate",
              toPath: "/packAssets/assetsCenter/index",
              query: {},
              tips: "",
            },
            {
              name: "我的推广海报",
              toType: "navigate",
              toPath: "/packAssets/mySharePoster/index",
              query: {},
              tips: "",
            },
            {
              name: "账户余额",
              toType: "navigate",
              toPath: "/packAssets/balance/index",
              query: {},
              tips: "",
            },
            {
              name: "客户",
              toType: "navigate",
              toPath: "/packAssets/clientPage/index",
              query: {},
              tips: "",
            },

            {
              name: "我的全部订单",
              toType: "navigate",
              toPath: "/packOrder/shop/list/index",
              query: {},
              tips: "",
            },
            {
              name: "我的全部门店订单",
              toType: "navigate",
              toPath: "/packOrder/store/list/index",
              query: {},
              tips: "",
            },
            {
              name: "我的全部拼团订单",
              toType: "navigate",
              toPath: "/packOrder/groupBuying/list/index",
              query: {},
              tips: "",
            },
            {
              name: "我的全部幸运团订单",
              toType: "navigate",
              toPath: "/packOrder/lucklyBuying/list/index",
              query: {},
              tips: "",
            },

            {
              name: "商城售后订单",
              toType: "navigate",
              toPath: "/packOrder/shop/rightsLog/index",
              query: {},
              tips: "",
            },
            {
              name: "门店售后订单",
              toType: "navigate",
              toPath: "/packOrder/store/rightsLog/index",
              query: {},
              tips: "",
            },
            {
              name: "拼团售后订单",
              toType: "navigate",
              toPath: "/packOrder/groupBuying/rightsLog/index",
              query: {},
              tips: "",
            },
            {
              name: "幸运团售后订单",
              toType: "navigate",
              toPath: "/packOrder/lucklyBuying/rightsLog/index",
              query: {},
              tips: "",
            },
            {
              name: "分销商",
              toType: "navigate",
              toPath: "/packIncome/distribution/index",
              query: {},
              tips: "",
            },
            {
              name: "收银台",
              toType: "navigate",
              toPath: "/packSub/cashier/index",
              query: {},
              tips: "",
            },
            {
              name: "团队分红",
              toType: "navigate",
              toPath: "/packIncome/teamDividend/index",
              query: {},
              tips: "",
            },
          ],
        },
      ],
      // 窗口显示
      boxVisible: false,

      query: {
        name: "",
        value: "",
      },
    };
  },
  methods: {
    // 在线客服
    onlineCustomerClick() {
      this.selected.name = "客服链接";
      this.selected.query = {};
      this.selected.path = "ONLINE_CUSTOMER";
      this.selected.type = "navigate";
    },
    // 选择装修模板 回调
    desginTemplateChange(r) {
      console.error("desginTemplateChange", r);
      this.selected.name = r.name;
      this.selected.query = { id: r.id };
      this.selected.path = r.path;
      this.selected.type = "navigate";
    },
    // 选择商品 回调
    goodsListChange(r) {
      console.error("goodsListChange", r);
      this.selected.name = r.name;
      this.selected.query = { id: r.id };
      this.selected.path = r.path;
      this.selected.type = "navigate";
    },
    // 选择门店分类 回调
    storeGroupChange(r) {
      console.error("storeGroupChange", r);
      this.selected.name = r.name;
      this.selected.query = { groupId: r.groupId };
      this.selected.path = r.path;
      this.selected.type = "navigate";
    },
    // 删除 自定义链接 参数
    delQuery(key) {
      console.error("key", key);
      this.$delete(this.selected.query, key);
    },
    addQuery() {
      if (!this.$vFN.Utils.isEmpty(this.selected.query[this.query.name])) {
        this.$vFN.Tools.messageError("参数名重复！");
        return;
      }
      if (this.$vFN.Utils.isEmpty(this.query.name)) {
        this.$vFN.Tools.messageError("参数名不能为空！");
        return;
      }
      if (this.$vFN.Utils.isEmpty(this.query.value)) {
        this.$vFN.Tools.messageError("参数值不能为空！");
        return;
      }
      if (!/^[a-zA-Z]/.test(this.query.name)) {
        this.$vFN.Tools.messageError("需以大小写字母开头");
        return;
      }

      this.$set(this.selected.query, this.query.name, this.query.value);
      this.query.name = "";
      this.query.value = "";
    },
    openUrl() {
      window.open(this.selected.path);
      // window.location.href = this.selected.path
    },
    // 选择
    selectItem(item_) {
      this.selected = {
        path: item_.toPath,
        type: item_.toType,
        name: item_.name,
        query: item_.query,
      };
      // this.toTypeOption(item_.toTypeList);
    },
    // // 生成跳转下拉数据选项
    // toTypeOption(data_) {
    //     let _list = [];
    //     data_.forEach((item) => {
    //         let _obj = this.$vFN.Tools.getLinkTypeOption(item);
    //         _list.push(_obj);
    //     });
    //     this.typeOption = _list;
    // },
    // 切换类型
    setSelectedIndex(index_) {
      this.selectedIndex = index_;
      // if (index_ == 101) {
      //     this.selectItem({
      //         toPath: "",
      //         toType: "navigate",
      //         query: {},
      //         name: "自定义内链",
      //         toTypeList: ["navigate", "reLaunch", "redirect"],
      //     });
      // }
      // if (index_ == 102) {
      //     this.selectItem({
      //         toPath: "",
      //         toType: "locationHref",
      //         name: "自定义外链",
      //         query: {},
      //         toTypeList: ["locationHref"],
      //     });
      // }
    },
    submit() {
      let _str = "";
      try {
        _str = JSON.stringify(this.selected);
      } catch (e) {}
      this.onSuccess(_str);
      this.editBoxClose();
    },
    // 成功回调
    onSuccess() {},
    // 取消回调
    onCancel() {},
    // 失败回调
    onError() {},
    // 关闭窗口
    editBoxClose() {
      this.boxVisible = false;
    },
    // 取消
    editBoxCancel() {
      this.editBoxClose();
    },
  },
  watch: {},
  mounted() {
    this.boxVisible = true;
    let _d = {};
    if (!this.$vFN.Utils.isEmpty(this.selected)) {
      try {
        _d = JSON.parse(this.selected);
      } catch (e) {}
    }

    this.selected = {
      name: _d["name"],
      path: _d["path"],
      type: _d["type"],
      query: _d["query"],
    };
  },
  beforeCreate() {},
};
</script>